﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class Admin_Parts_ViewProduct : System.Web.UI.UserControl
{
    private SqlConnection connSql;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Session["SID"] = "";
            //DataSet ds1 = loaddmc();
            //drldmc.DataTextField = "ParentCatName";
            //drldmc.DataValueField = "ParentCatID";
            //drldmc.DataSource = ds1.Tables[0];
            //drldmc.DataBind();
            //DataSet ds = loadnxb();
            //drlnxb.DataTextField = "ProviderName";
            //drlnxb.DataValueField = "ProviderID";
            //drlnxb.DataSource = ds.Tables[0];
            //drlnxb.DataBind();

        }


        //GridView1.DataSource = ds1.Tables[0];
        //GridView1.DataBind();

    }

    public DataSet loadnxb()
    {
        ConnectionStringSettings connSett;
        connSett = ConfigurationManager.ConnectionStrings["ConnectionString"];
        string connStr = connSett.ConnectionString;
        connSql = new SqlConnection(connStr);
        SqlDataAdapter daDepart = null;
        daDepart = new SqlDataAdapter("SELECT * FROM NhaCungCap", connSql);
        DataSet ds = new DataSet();
        daDepart.Fill(ds);
        return ds;
    }

    public DataSet loaddmc()
    {
        ConnectionStringSettings connSett;
        connSett = ConfigurationManager.ConnectionStrings["ConnectionString"];
        string connStr = connSett.ConnectionString;
        connSql = new SqlConnection(connStr);
        SqlDataAdapter daDepart = null;
        daDepart = new SqlDataAdapter("SELECT * FROM DanhMucCha", connSql);
        DataSet ds = new DataSet();
        daDepart.Fill(ds);
        return ds;
    }

    public DataSet loadinfoconnect(String ProviderID)
    {
        ConnectionStringSettings connSett;
        connSett = ConfigurationManager.ConnectionStrings["ConnectionString"];
        string connStr = connSett.ConnectionString;
        connSql = new SqlConnection(connStr);
        SqlDataAdapter daDepart = null;
        daDepart = new SqlDataAdapter("SELECT * FROM NhaCungCap where ProviderID='" + ProviderID + "'", connSql);
        DataSet ds = new DataSet();
        daDepart.Fill(ds);
        return ds;
    }

    protected void btnketnoi_Click(object sender, EventArgs e)
    {
        //DataSet ds = loadinfoconnect(drlnxb.SelectedValue.ToString());
        //DataRow dr = ds.Tables[0].Rows[0];
        //object result = WSProxy.CallWebService("http://localhost:1553/WS%20NSX/Service.asmx", "Service", "WSLogin", new object[] { dr["PartnerID"].ToString(), dr["PartnerPwd"].ToString() });

        //result = ChangeType(result, "String");
        //Session["SID"] = result.ToString();
        //if (Session["SID"].ToString() != "-1" && Session["SID"].ToString() != "")
        //{
        //    Response.Write("<script> alert('Kết nối thành công') </script>");
        //}
        //else
        //{
        //    Response.Write("<script> alert('Kết nối thất bại') </script>");
        //}
    }

    public object ChangeType(object ob, String str)
    {
        if (str == "String")
            ob = Convert.ChangeType(ob, typeof(String));
        if (str == "Int")
            ob = Convert.ChangeType(ob, typeof(Int32));
        if (str == "Boolean")
            ob = Convert.ChangeType(ob, typeof(Boolean));
        if (str == "Float")
            ob = Convert.ChangeType(ob, typeof(float));
        if (str == "Data")
            ob = Convert.ChangeType(ob, typeof(DataTable));
        return ob;
    }

    protected void drldm_SelectedIndexChanged(object sender, EventArgs e)
    {
        //object obj = ServiceConsumer.WSProxy.CallWebService("", "", new object[] { });
        //String str = drldm.SelectedValue.ToString();
        //object result1 = WSProxy.CallWebService("http://localhost:1553/WS%20NSX/Service.asmx", "Service", "Product", new object[] { str });
        //result1 = ChangeType(result1, "Data");
        ////DataTable dt = result;
        //GridView1.DataSource = result1;
        //GridView1.DataBind();
        ////DataSet ds = loadnxb();
        ////drldm.DataTextField = "CatName";
        ////drldm.DataValueField = "CatId";
        ////drldm.DataSource = result1;
        ////drldm.DataBind();
        //drldmc.SelectedValue = str;

    }

    protected void drldmc_SelectedIndexChanged(object sender, EventArgs e)
    {

        //String str = drldmc.SelectedValue.ToString();
        //String SID = "";
        //SID = Session["SID"].ToString();
        //if (SID != "-1" && SID != "")
        //{
        //    object result1 = WSProxy.CallWebService("http://localhost:1553/WS%20NSX/Service.asmx", "Service", "Category", new object[] { str });
        //    result1 = ChangeType(result1, "Data");
        //    //DataTable dt = result;
        //    //GridView1.DataSource = result1;
        //    //GridView1.DataBind();
        //    //DataSet ds = loadnxb();
        //    drldm.DataTextField = "CatName";
        //    drldm.DataValueField = "CatId";
        //    drldm.DataSource = result1;
        //    drldm.DataBind();
        //}
        //else if (SID == "-1" || SID == "")
        //{
        //    Response.Write("<script>alert('Chưa kết nối')</script>");
        //}
        //drldmc.SelectedValue = str;
    }
}